﻿namespace Dcms.UpdateModule
{
    using Dcms.BaseClass;
    using System;
    using System.Reflection;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class DcmsOperateModel : Dcms.BaseClass.DcmsOperateModel
    {
        public override void aInitSetValue(Control ctl, object oValue)
        {
            if (ctl.GetType().ToString() == "System.Web.UI.WebControls.Literal" && oValue != null && oValue.ToString() != "")
            {
                Literal literal = (Literal) ctl;
                literal.Text = "<samp onmouseover=\"ShowImage('" + oValue.ToString() + "');\" onmouseout=\"HideImage();\">查看</samp>";
            }
            string str = ctl.GetType().ToString();
            if (str != null)
            {
                if (!(str == "System.Web.UI.WebControls.TextBox"))
                {
                    if (str == "System.Web.UI.WebControls.RadioButtonList")
                    {
                        RadioButtonList list = (RadioButtonList) ctl;
                        list.SelectedValue = oValue.ToString();
                    }
                    else if (str == "System.Web.UI.WebControls.DropDownList")
                    {
                    }
                }
                else
                {
                    TextBox box = (TextBox) ctl;
                    box.Text = oValue.ToString();
                }
            }
        }

        public override void aSetControlValue(string strFieldID, PropertyInfo property, object model, Control ctl)
        {
            if (ctl.GetType().ToString() != "System.Web.UI.WebControls.Literal" && string.Compare(strFieldID, property.Name, true) == 0)
            {
                string str = property.PropertyType.ToString();
                if (str == null) goto Label_00A1;
                if (!(str == "System.DateTime"))
                {
                    if (str == "System.Int32")
                    {
                        property.SetValue(model, Convert.ToInt32(this.GetControlValue(ctl)), null);
                        return;
                    }
                    goto Label_00A1;
                }
                property.SetValue(model, Convert.ToDateTime(this.GetControlValue(ctl)), null);
            }
            return;
        Label_00A1:
            property.SetValue(model, this.GetControlValue(ctl), null);
        }

        public string GetControlCondition(string WebContrlIdStr, ControlCollection Controls)
        {
            foreach (Control control in Controls)
            {
                if (control.ID == WebContrlIdStr) return this.GetControlValue(control);
            }
            return "";
        }

        private string GetControlValue(Control ctl)
        {
            string str = "";
            string str3 = ctl.GetType().ToString();
            if (str3 == null) return str;
            if (!(str3 == "System.Web.UI.WebControls.TextBox"))
            {
                if (str3 != "System.Web.UI.WebControls.RadioButtonList")
                {
                    if (str3 == "System.Web.UI.WebControls.Literal")
                    {
                        Literal literal = (Literal) ctl;
                        return literal.Text;
                    }
                    if (str3 == "System.Web.UI.WebControls.DropDownList")
                    {
                    }
                    return str;
                }
            }
            else
            {
                TextBox box = (TextBox) ctl;
                return box.Text;
            }
            RadioButtonList list = (RadioButtonList) ctl;
            return list.SelectedValue;
        }

        public static void InitModel(object model)
        {
            foreach (PropertyInfo info in model.GetType().GetProperties())
            {
                string str2 = info.PropertyType.ToString();
                if (str2 != null)
                {
                    if (!(str2 == "System.String"))
                    {
                        if (str2 == "System.DateTime") goto Label_0069;
                        if (str2 == "System.Byte[]") goto Label_0085;
                    }
                    else
                        info.SetValue(model, "", null);
                }
                goto Label_0096;
            Label_0069:
                info.SetValue(model, new DateTime(0x76c, 1, 1), null);
                goto Label_0096;
            Label_0085:
                info.SetValue(model, new byte[0], null);
            Label_0096:;
            }
        }
    }
}

